<template>
  <div class="home">
    <img alt="Vue logo" src="../assets/logo.png" @click="debouncedClick" />
    <div>{{ $t("app.a") }}</div>
    <HelloWorld msg="Welcome to Your Vue.js App" />
  </div>
</template>

<script>
import _ from "lodash";

export default {
  created() {
    // 用 Lodash 的防抖函数
    this.debouncedClick = _.debounce(this.click, 500);
  },
  unmounted() {
    // 移除组件时，取消定时器
    this.debouncedClick.cancel();
  },
  methods: {
    click() {
      if (this.$i18n.locale == "zh") {
        this.$i18n.locale = "en";
      } else {
        this.$i18n.locale = "zh";
      }
      console.log(1);
    },
  },
};
</script>
